[t:/]$ 지식_

web2py lazy table

2014/09/15

http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#markmin_lazy_tables

그러니까.. web2py 구조상 매 리퀘스트마다 table define을 다시 하는데... -_-;

lazy_table 옵션을 켜 두면 필요할 때 임박해서야 콜 한다는 뜻이다.

보통은 define_table 펑션 류에 인스턴스가 이미 있느냐 없느냐에 따라 바로 리턴하는 코드를 박아두는 모양인데... 로그 상 관측해보면 바로 리턴 안 하는 것 같다? 그러니까 생명 주기가 리퀘스트-리스판스 한 턴이라서 인스턴스 재사용이 안 되는 듯...

뭐 이렇게 만들어놨냐.. 메모리 관리는 깔끔해서 나도 이런 쪽을 선호하기는 하는데... fire & forgot.. 이런 형식은 좀 애매하다. 사상적 차이인듯. 여튼 선호하는 방식이긴하다...

Lazy Tables, a major performance boost web2py models are executed before controllers, so all tables are defined at every request. Not all tables are needed to handle each request, so it is possible that some of the time spent defining tables is wasted. Conditional models (conditional models, chapter 4) can help, but web2py offers a big performance boost via lazy_tables. This feature means that table creation is deferred until the table is actually referenced. Enabling lazy tables is made when initialising a database via the DAL constructor. It requires setting theDAL(...,lazy_tables=True) parameter. This is one of the most significant response-time performance boosts in web2py.









[t:/] is not "technology - root". dawnsea, rss